<!DOCTYPE html >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1">
    <title>洋店街</title>
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <link href="css/zhuce.css" type="text/css" rel="stylesheet"/>
    <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
   
    <script type="text/javascript">
    	var code1;
		var timer;
		function dingshi(date){
				if($("#hqyzm").attr("disabled")!="disabled"){
					$("#hqyzm").attr("disabled","disabled"); 
				}
				var nowdate = new Date().getTime();
				var cha=Math.ceil((date-nowdate)/1000);
				if(cha>0){
					$("#hqyzm").text(cha+"s后重发");
				}else if(cha==0){
					$("#hqyzm").removeAttr("disabled");
					$("#hqyzm").text("重新获取");
					window.clearInterval(timer);
				}
		}
    
    	function checkNull(tag,message){
				var flag = true;	
				if(tag.val()==null||tag.val()==""){
					flag = false;
					tag.next()[0].innerText=message;
				}else{
					tag.next()[0].innerText="";
				}
				return flag;
			}
			
			function checkPassWord(pass1,pass2){
				var flag = true;
				if(pass1.val()!=pass2.val()){
					flag = false;
					pass1.next()[0].innerText="两次密码不一致";
					pass2.next()[0].innerText="两次密码不一致";
				}else{
					pass1.next()[0].innerText="";
					pass2.next()[0].innerText=""; 
				}
				return flag;
			}
			
			
			$(document).ready(function(){
				$("#userName").change(function(){
					var flag = checkNull($("#userName"),"用户名不能为空");
					if(flag){
						$("#yhmspan").html("");
						$.ajax({
							type:"post",
							data:{"yhm":$("#userName").val()},
							url:"../jianchayhm.do",
							datatype:"json",
							success:function(data){
								var flag = eval(data);
								if(!flag){
									$("#yhmspan").text("用户名被占用,请更换！");
								}else{
									$("#yhmspan").text("");
								}
							}
						});
					}else{
						$("#yhmspan").text("用户名不能为空");
					}
				});
				function mobelPhoneYZ(mobelphone,message){
					 var reg = /^1[3|4|5|7|8][0-9]{9}$/;
					var flag = false;
					if(reg.test(mobelphone.val())){
						mobelphone.next()[0].innerText="";
						flag = true;
					}else{
						mobelphone.next()[0].innerText=message;
					}
					return flag;
				}
				
				//获取验证码
				$("#hqyzm").click(function(){
					var phonenumber = $("#phonenumber");
					var flag = checkNull(phonenumber,"请先填写手机号");
					if(flag){
						var flag2 = mobelPhoneYZ(phonenumber,"手机号码非法！")
						//生成验证码，并发送至指定的手机
						if(flag2){
							//	符合条件提交数据
							$.ajax({
								type:"post",
								url:"/sendSms",
								data:"phoneNumber="+phonenumber.val()+"&flag="+1,//flag用来标识是注册发送验证码还是登录需要发送验证码
								dataType:"json",
								success:function(data){
									if(data!=null&&data!=""){
										code=data;
										$("#code").val(code);
										var date = new Date().getTime()+60000;
										window.setInterval("dingshi("+date+")", 1000);
									}else{
										alert("发送失败");
									}
								},
								error:function(){
									alert("请求失败");
								}
							
							});
						}
					}
				
				});
				
				$("#zhuceForm").submit(function(event){
					event.preventDefault();
					var yhm = $("#userName");
					var yhmm1 = $("#passWord");
					var yhmm2 = $("#passWord2");
					var yhdh = $("#phonenumber");
					var flag1 = checkNull(yhm,"用户名不能为空");
					var flag2 = checkNull(yhmm1,"密码不能为空");
					var flag3 = checkNull(yhmm2,"确认密码不能为空");
					var flag4 = false;
					if(flag2&&flag3){
						flag4 = checkPassWord(yhmm1,yhmm2)
					}
					var flag5 = checkNull(yhdh,"手机号码不能为空");
					var flag6 = false;
					//说明手机号码不为空
					if(flag5){
						flag6 = mobelPhoneYZ(yhdh,"手机号码非法！")
					}
					var flag7 = false;
					var flag8 = false;
					//说明手机号码合法
					if(flag6){
						$.ajax({
							type:"post",
							async:false,
							data:"phoneNumber="+yhdh.val(),
							url:"../jiachayhdh.do",
							datatype:"json",
							success:function(data){
								data = eval("("+data+")");
								if(!data){
									alert("该电话号码已经绑定其他账号，请更换~");
								}else{
									flag8 = true;
								}
							}
							
						
						});
						if($("#yzm").val()==null||$("#yzm").val()==""){
							alert("请选填写获取到的验证码!");
						}else if($("#code").val()!=null&&$("#code").val()!=""){
							if($("#yzm").val()!=$("#code").val()){
								alert("验证码输入有误，请核对!");
							}else{
								flag7 = true;
							}
						}
					}
					
					if(flag1&&flag2&&flag3&&flag4&&flag5&&flag6&&flag7&&flag8){
						$.ajax({
							type:"post",
							async:false,
							data:{"loginname":yhm.val(),"password":yhmm1.val(),"phoneNumber":yhdh.val()},
							url:"/GSCMS_SSM/zhuCe.do",
							datatype:"json",
							success:function(data){
								if(data){
									alert("恭喜您注册成为我们的新用户,请使用新账号登录...");
									window.location.href="login.html";
								}else{
									alert("很遗憾本次注册失败，不要灰心请尝试重新注册...");
								}
							}
						
						});
					}
					
				});
				
			
			});
		
    </script>
</head>
<body>
<!---------------头部----------------->
<!--<div class="wt1080 top">
    <div class="logo"><a href="#"><img src="image/logo.png"></a></div>
    <div class="rr">
        <ul>
            <li>
                <img src="image/bg3.png">
                <p>全球正品货源</p>
            </li>
            <li>
                <img src="image/bg5.png">
                <p>一件代发</p>
            </li>
            <li>
                <img src="image/bg4.png">
                <p>全球直邮</p>
            </li>
            <li>
                <img src="image/bg6.png">
                <p>售后无忧</p>
            </li>
        </ul>
    </div>
    <div class="clear"></div>
</div>-->
<!----------------------中间------------------------->
<form action="" id="zhuceForm">
<div class="red">
    <div class="wt1080 login">
        <div class="login_pic"><img src="images/login.jpg"></div>
        <div class="l_k">
            <h1>新用户注册</h1>
            <div class="l_k_d">用户名：<input type="text" id="userName" placeholder="用户名"/><span id="yhmspan" style="color:red;font-size: 20px"></span></div>
            <div class="l_k_d">设置密码：<input type="password" id="passWord" placeholder="大小写英文字母、符号或数字"/><span style="color:red;font-size: 20px" id="passwordspan"></span></div>
            <div class="l_k_d">确认密码：<input type="password" id="passWord2" placeholder="请再次输入密码"/><span style="color:red;font-size: 20px " id="password2span"></span></div>
            <div class="l_k_d">手机号码：<input type="text" id="phonenumber" placeholder="请输入手机号码"/><span style="color:red;font-size: 20px " id="phonenumberspan"></span></div>
            <div class="l_k_s" >验证码：<input type="text" name="yzm" id="yzm" placeholder="6位验证码"></div>
          	<div class="verify" id="hqyzm">点击获取</div>
            <p>点击注册，表示你同意洋店网<a href="#">《服务协议》</a></p>
            <input type="hidden" id="code"/>
            <input name="" type="submit" class="res" value="注册">
        </div>
    
        <div class="clear"></div>
    </div>
</div>
  </form>  
<!-------------------底部------------------------>
<!--<div class="foot wt1080">
    <ul>
        <li><a href="#">网站简介</a></li>
        <li><a href="#">联系我们</a></li>
        <li><a href="#">招商合作</a></li>
        <li><a href="#">销售联盟</a></li>
    </ul>
    <p>Copyright © 2016 洋店网.版权所有.备案号：京ICP证35124521号.技术支持：网站建设</p>
</div>-->

</body>
</html>
